๐Ÿ”ฅFinal Project Day 4 - Grid Place Items

๐ŸŒตPlace Items on Grid

<body>
  <div class="grid">
    <div class="header">header</div>
    <div class="content">content</div>
    <div class="nav">nav</div>
    <div class="footer">footer</div>
  </div>
</body>

๊ฐ๊ฐ์˜ div ๋“ค์€ (.header, .content, .nav, .footer) ์ปจํ…์ธ  (text) ๋ฅผ ๊ฐ€์ง€๊ณ  ์žˆ๋‹ค.

์•„์ดํ…œ๋“ค์„ ์œ„์น˜์‹œํ‚ค๋Š” justify-items ์™€ align-items ์— ๋Œ€ํ•ด ์•Œ์•„๋ณด์•˜๋‹ค.

๋งˆ์ฐฌ๊ฐ€์ง€๋กœ ๋ถ€๋ชจ ์†์„ฑ์—์„œ (.grid) ์‚ฌ์šฉํ•œ๋‹ค.

์•„๋ž˜๋Š” ์ดˆ๊ธฐ ์ฝ”๋“œ์ด๊ณ  ์—ฌ๊ธฐ์— justify-items ์™€ align-items ๋ฅผ ์ ์šฉ์‹œ์ผœ ๋ณด๊ฒ ๋‹ค.

.grid {
  display: grid;
  gap: 10px;
  height: 50vh;
  grid-template-columns: repeat(4, 1fr);
  grid-template-rows: repeat(4, 1fr);
}

.header {
  background: #2ecc71;
}
.content {
  background: #3498db;
}
.nav {
  background: #8e44ad;
}
.footer {
  background: #f39c12;
}

๐ŸŒตjustify-items: stretch (by default)

justify-items: stretch;

justify-items(์ˆ˜ํ‰, ๊ฐ€๋กœ), stretch ๊ฐ€ ๊ธฐ๋ณธ ๋””ํดํŠธ ์ด๋‹ค.

stretch ๋Š” grid-container ๊ฐ€ grid ๋ฅผ ๊ฐ€์ง€๊ณ  ์žˆ๊ณ  grid ๋ฅผ ๋Š˜์—ฌ์„œ grid ์ž์ฒด๋ฅผ ์ฑ„์šฐ๋„๋ก ํ•œ๋‹ค.

๊ทธ๋Ÿฐ๋ฐ justify-items ๋ฅผ start, center, end ๋กœ ๋ฐ”๊ฟ”๋ณด๋ฉด ์•„๋ž˜ ๊ทธ๋ฆผ๊ณผ ๊ฐ™๋‹ค.

justify-items: start;

start

justify-items: center;

center

justify-items: end;

end

๐ŸŒตalign-items: stretch (by default)

์œ„์™€ ๋งˆ์ฐฌ๊ฐ€์ง€ ์ด์ง€๋งŒ align-items (์ˆ˜์ง, ์„ธ๋กœ) ๋ฐฉํ–ฅ์— ์‚ฌ์šฉ๋œ๋‹ค๋Š” ์ ์ด ๋‹ค๋ฅด๋‹ค.

์ด ๋˜ํ•œ start, center, end ์˜ต์…˜์„ ์ค„ ์ˆ˜ ์žˆ๋‹ค.

๐ŸŒตjustify-items ์™€ align-items ๋™์‹œ ์‚ฌ์šฉํ•˜๊ธฐ

justify-items ์™€ align-items ๊ฐ€ stretch ๊ฐ€ ์•„๋‹ˆ๋ฉด์„œ ๊ฐ ์•„์ดํ…œ์˜ content ๊ฐ€ ์—†์„ ๊ฒฝ์šฐ (text) ๋ธŒ๋ผ์šฐ์ €์—๋Š” ์—ญ์‹œ ์•„๋ฌด๊ฒƒ๋„ ์•ˆ๋‚˜์˜จ๋‹ค.

๋†’์ด์™€ ๋„ˆ๋น„๊ฐ€ ์—†๊ธฐ ๋•Œ๋ฌธ์ด๋‹ค. ํ•˜์ง€๋งŒ stretch ์ผ ๋•Œ๋Š” ์ปจํ…์ธ (text) ๊ฐ€ ์žˆ๊ณ  ์—†๊ณ ๋ฅผ ๋– ๋‚˜์„œ ๋ธŒ๋ผ์šฐ์ €์— ๋‚˜์˜จ๋‹ค. ์™œ?์ผ๊นŒ?

๊ทธ๋ž˜์„œ header, content, nav, footer ํด๋ž˜์Šค์— ๋†’์ด์™€ ๋„ˆ๋น„๋ฅผ 40px ๋กœ ๋ถ€์—ฌํ•˜๊ณ  justify-items ์™€ align-items ๋ฅผ ๋™์‹œ ์‚ฌ์šฉํ•ด ๋ณด์•˜๋‹ค.

justify-items: end;
align-items: start;

์—ฌํŠผ ๊ฐ ํด๋ž˜์Šค ๋ณ„๋กœ height, width ๋ฅผ ๋ถ€์—ฌํ•˜๋ฉด ๋‚˜ํƒ€๋‚œ๋‹ค.

mixed

๊ธฐ๋ณธ ์‚ฌ์ด์ฆˆ๋ฅผ (width, height) ๋ถ€์—ฌํ•˜๋ฉด justify-items, align-items ์— stretch ๋ฅผ ์ค˜๋„ ๋Š˜์–ด๋‚˜์ง€ ์•Š๋Š”๋‹ค.

์ด๋ฏธ ๊ธฐ๋ณธ ์‚ฌ์ด์ฆˆ๋ฅผ ์ง€์ •ํ•ด ์คฌ๊ธฐ ๋•Œ๋ฌธ์ด๋‹ค.

๐ŸŒตjustify-items ์™€ align-items ์˜ shortcut, place-items

justify-items ์™€ align-items ๋ฅผ ํ•œ ์ค„๋กœ ์ž‘์„ฑํ•  ์ˆ˜ ์žˆ๋Š” shortcut ์ด ์žˆ๋‹ค.

๊ธฐ๋ณธ ํ˜•ํƒœ๋Š”

place-items: ์ˆ˜์ง y ์ˆ˜ํ‰ x; ์˜ ํ˜•ํƒœ๋กœ ์ž‘์„ฑํ•œ๋‹ค.

place-items: stretch center;

Written by@[DotoriMook]
ํ”„๋ก ํŠธ์—”๋“œ ์ฃผ๋‹ˆ์–ด ๊ฐœ๋ฐœ์ž ๋„ํ† ๋ฆฌ๋ฌต์˜ ๊ธฐ์ˆ ๊ฐœ๋ฐœ ๋ธ”๋กœ๊ทธ ์ž…๋‹ˆ๋‹ค.

GitHubMediumTwitterFacebook